package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.UserInfo;
import com.itheima.mapper.UserInfoMapper;
import com.itheima.service.db.UserInfoService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    // 保存用户信息
    @Override
    public void save(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    // 更新用户信息
    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    // 根据id查询
    @Override
    public UserInfo findByUserId(Long userId) {
        return userInfoMapper.selectById(userId);
    }

    // 分页查询
    @Override
    public PageBeanVo findByPage(Integer pageNum, Integer pageSize) {
        //1.设置分页参数
        Page<UserInfo> page = new Page<>(pageNum, pageSize);
        //2.创建条件对象
        //3.执行分页操作
        userInfoMapper.selectPage(page, null);
        //4.封装pageBeanvo返回
        return new PageBeanVo(pageNum, pageSize, page.getTotal(), page.getRecords());
    }

    @Override
    public UserInfo selectUser(Long userId) {
        UserInfo userInfo = userInfoMapper.selectById(userId);
        return userInfo;
    }
}
